package cn.jinhaze.controller;


import cn.jinhaze.entity.ObjectData;
import cn.jinhaze.entity.PageResult;
import cn.jinhaze.entity.ResultData;
import cn.jinhaze.service.ICoreService;
import cn.jinhaze.utils.HttpsUtils;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/core")
@RequiredArgsConstructor
public class CoreController {

    private final ICoreService coreService;

    @GetMapping("/start/{pageNum}/{pageSize}")
    public String start(@PathVariable Integer pageNum, @PathVariable Integer pageSize) throws Exception {
        int process = coreService.process(pageNum, pageSize);
        return "成功抓取到" + process + "条数据";
    }


    @GetMapping("/getMySQL/{pageNum}/{pageSize}")
    public String getMySQL(@PathVariable Integer pageNum, @PathVariable Integer pageSize) throws Exception {
        List<ObjectData> list = coreService.getMySQL(pageNum, pageSize);
        return JSON.toJSONString(list);
    }

    @GetMapping("getMongo/{pageNum}/{pageSize}")
    public String getMongo(@PathVariable Integer pageNum, @PathVariable Integer pageSize) throws Exception {
        List<ObjectData> list = coreService.getMongo(pageNum, pageSize);
        return JSON.toJSONString(list);
    }
}
